package com.notes.config.api;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author: huxingxin
 * @Date: 2024/1/9
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "响应参数", description = "用于返回响应的数据")
public class ApiResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "状态码")
    private int code;
    @ApiModelProperty(value = "状态信息")
    private String message;
    @ApiModelProperty(value = "响应数据")
    private T data;

    public static <T> ApiResult<T> success(){
        return new ApiResult<>(200, "请求成功", null);
    }

    public static <T> ApiResult<T> success(String message){
        return new ApiResult<>(200, message, null);
    }

    public static <T> ApiResult<T> success(T data){
        return new ApiResult<>(200, "请求成功", data);
    }

    public static <T> ApiResult<T> success(String message, T data){
        return new ApiResult<>(200, message, data);
    }

    public static <T> ApiResult<T> error(){
        return new ApiResult<>(500, "请求失败", null);
    }

    public static <T> ApiResult<T> error(String message){
        return new ApiResult<>(500, message, null);
    }
}
